<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="大屏id" prop="screenId">
        <el-input
          v-model="queryParams.screenId"
          placeholder="请输入大屏id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="大屏名称" prop="screenName">
        <el-input
          v-model="queryParams.screenName"
          placeholder="请输入大屏名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="提取码" prop="extractionNumber">
        <el-input
          v-model="queryParams.extractionNumber"
          placeholder="请输入提取码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分享人" prop="senderId">
        <el-input
          v-model="queryParams.senderId"
          placeholder="请输入分享人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="shareTokenList" >
      <el-table-column label="大屏id" align="screen_id" prop="screenId" />
      <el-table-column label="大屏名称" align="center"  prop="screenName" />
      <el-table-column label="提取码" align="center"  prop="extractionNumber" />
      <el-table-column label="分享人" align="center"  prop="senderId" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="有效时间(天)" align="center" prop="effectiveTime" />
      <el-table-column label="过期时间" align="center" prop="expirationTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="recoverShareToken(scope.row)"
          >恢复</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { listShareToken,recoverToken} from "@/api/tool/shareToken";

export default {
  
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // shareToken列表
      shareTokenList: [],
      // 弹出层标题
      title: "",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 需要恢复的token列表 */
    getList() {
      this.loading = true;
      listShareToken(this.queryParams).then(response => {
        this.shareTokenList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    
    /** 恢复按钮操作 */
    recoverShareToken(row) {
      recoverToken(row).then(res=>{
        if(res.code == 200){
          this.msgSuccess("恢复成功");
        }else{
          this.msgError("恢复失败");
        }
        this.getList();
      })
    },
    
  }
};
</script>